﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Composite.Core.Routing;
using System.Collections.Specialized;

namespace LCA.Utils
{
    /// <summary>
    /// Summary description for UrlHelper
    /// </summary>
    public class UrlHelper
    {
        public static string GetMediaUrl(string mediaPath)
        {
            if (string.IsNullOrEmpty(mediaPath))
                return null;

            if (!mediaPath.Contains(":"))
                return null;

            string[] parts = mediaPath.Split(new[] { ':' });

            string mediaStore = parts[0];
            Guid mediaId = new Guid(parts[1]);

            string mediaUrl = MediaUrls.BuildUrl(new MediaUrlData { MediaStore = mediaStore, MediaId = mediaId, QueryParameters = new NameValueCollection() },
                                                 UrlKind.Public);

            // Temporary fix, allows media player to receive a nice url with an extension
            return mediaUrl.Replace("_jpg", ".jpg").Replace("_mov", ".mov").Replace("_m4v", ".m4v").Replace("_swf", ".swf");
        }
    }
}
